"当前可用版本：
"  VIM - Vi IMproved 9.1 (2024 Jan 02, compiled Jan 16 2025 20:13:18)


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" => Fn 快捷键
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"F1 for uncomment
"Vim help
nnoremap <F1> :vertical botright help<CR>

"F6 for uncomment
vmap <F6> :s=^\(//\)*==g<cr>:noh<cr>
nmap <F6> :s=^\(//\)*==g<cr>:noh<cr>
imap <F6> <ESC>:s=^\(//\)*==g<cr>:noh<cr>

"F7 for uncomment
vmap <F7> :s=^\(//\)*=//=g<cr>:noh<cr>
nmap <F7> :s=^\(//\)*=//=g<cr>:noh<cr>
imap <F7> <ESC>:s=^\(//\)*=//=g<cr>:noh<cr>

"F12 for uncomment
vmap <F12> :s=^\(//\)*=/*=g<cr>:s=\(//\)*$= */=g<cr>:noh<cr>
nmap <F12> :s=^\(//\)*=/*=g<cr>:s=\(//\)*$= */=g<cr>:noh<cr>
imap <F12> <ESC>:s=^\(//\)*=/*=g<cr>:s=\(//\)*$= */=g<cr>:noh<cr>

"F9 for uncomment
vmap <F9> :s=^\(\/\*\)*==g<cr>:s=\(\ \*\/\)*$==g<cr>:noh<cr>
nmap <F9> :s=^\(\/\*\)*==g<cr>:s=\(\ \*\/\)*$==g<cr>:noh<cr>
imap <F9> <ESC>:s=^\(\/\*\)*==g<cr>:s=\(\ \*\/\)*$==g<cr>:noh<cr>


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" => 常用配置
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 将前缀键定义为逗号，默认为"\"
let mapleader = ";"

" 打开鼠标功能,所有模式
set mouse=a

" 光标上下两侧最少保留的屏幕行数,缩写“so”
set scrolloff=7

" 搜索时忽略大小写
set ignorecase
" 搜索智能匹配大小写
set smartcase

" 高亮显示搜索结果
set hlsearch
" 开启实时搜索功能
set incsearch

"" 设置格式化时制表符占用空格数
"set shiftwidth=4
"" 让 vim 把连续数量的空格视为一个制表符
"set softtabstop=4
"" 设置编辑时制表符占用空格数
"set tabstop=4
""set smarttab
"
"" 输入tab时自动将其转化为空格
"set expandtab
""set noexpandtab

" Linux kernel code style
"set expandtab
set noexpandtab

" 在处理未保存或只读文件的时候，弹出确认
"set confirm

" 去掉输入错误的提示声音
set noeb

" 高亮显示当前行/列
set cursorline
"set cursorcolumn

" 开启行号显示
set nu

" 分割线显示
" color set: ColorColumn
set colorcolumn=80
" Make it obvious where 80 characters is
"set textwidth=110
"set colorcolumn=+1

" 允许在未保存的情况下切换缓冲区,方便跳转
set hidden

" 将case 标记之后的语句放在标记缩进位置之后的 N 个字符处。(省缺'shiftwidth')。
set cinoptions=:N,lN,bN

" 文件备份与恢复
set nobackup
set nowb
set noswapfile

" 允许用指定语法高亮配色方案替换默认方案,文件$VIMRUNTIME/syntax
syntax on
" 强制Vim从文件的开头重新开始语法高亮同步, 该设置会影响打开文件的时间, 当前配置针对C语言相关
autocmd BufEnter *.[sS] :syntax sync fromstart                "从文件开头到文件结尾

" 开启文件类型侦测
filetype on
" 根据侦测到的不同类型加载对应的插件
" Enable filetype plugin
filetype plugin on
" 自适应不同语言的智能缩进
filetype indent on

" 开启模式行
"set modeline

" 外部更改文件时自动读取
set autoread

" 光标停留在上次打开的位置
autocmd BufReadPost * normal! g`"

" 关闭VIM内置补全的preview窗口
set completeopt-=preview

" 命令行Tab补全提示
set wildmenu
set wildmode=longest:full,full

" 标记tab缩进,开启后鼠标选择复制代码时会将标记也复制影响使用。
"set list lcs=tab:\|\ "后面是空格

" 会话的自动保存和加载
let g:AutoSessionFile="project.vim"
let g:OrigPWD=getcwd()
if filereadable(g:AutoSessionFile)
    if (argc() == 0)
        au VimEnter * call EnterHandler()
        au VimLeave * call LeaveHandler()
    endif
endif
function! LeaveHandler()
    exec "mks! ".g:OrigPWD."/".g:AutoSessionFile
endfunction
function! EnterHandler()
    exe "source ".g:AutoSessionFile
endfunction


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" => 快捷方式
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 插入当前时间
iab xdate <c-r>=strftime("%Y/%m/%d %H:%M:%S")<cr>

" 以unix格式显示换行符
nmap xsm :e ++ff=unix
" 以dos格式显示换行符
nmap xsm :e ++ff=dos

" 删除多余空格
nmap ds :%s/\s\+$//<cr>
nmap db :g/^$/d<cr>

" 删除多余空行只留一个空行
nmap dh :g/^\s*$\n\s*$/d<cr>

" 删除行尾的一个^M
nmap dm :%s/\r\+$//e<cr>:set ff=unix<cr>

" 格式化
" XML
function XML()
    set filetype=xml
    :%s/></>\r</g   "把><替换成>回车<
    :normal gg=G<cr>
endfunction
nmap xml :call XML()<cr>

map json :%!python -m json.tool<cr>

" 快捷打印
map dk  oprintk("===> func: %s, line: %d\n", __func__, __LINE__);<Esc>
map df  oprintf("===> func: %s, line: %d\n", __func__, __LINE__);<Esc>
map dff oprintf("===> func: %s, line: %d, file: %s\n", __func__, __LINE__, __FILE__);<Esc>

" Ctrl + s保存文件
nmap <C-S> :update<cr>
vmap <C-S> <C-C>:update<cr>
imap <C-S> <C-O>:update<cr>

" 显示tab缩进指示线
" note: there is a space after the last \ above
map lt :set list listchars=tab:\┊\ <cr>

" 在最下方水平打开一个终端
nmap <c-l> :botright term<cr>

" 高亮行尾空格
"autocmd FileType * highlight BadWhiteSpace ctermbg=124 guibg=Red
"autocmd FileType * match BadWhiteSpace /\s\+$/


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" => 文本编码
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" 设备vim解码列表
set fileencodings=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
"" 设备vim屏幕显示编码
"set termencoding=utf-8
"" 设备vim内部编码方式
"set encoding=utf-8
"" 设置文件的编码方式
"set fileencoding=utf-8


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" => 插件管理 vim-plug
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" https://github.com/junegunn/vim-plug
" 升级vim-plug:
" curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
"	https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

" 全局变量plug_url_format设置下载仓库地址，默认为github官网
" 国内镜像加速以下可用，2022/03/24 22:17:50
"let g:plug_url_format='https://git::@hub.fastgit.xyz/%s.git'
" 2022-12-16 升级可用
"let g:plug_url_format='https://github.91chi.fun/https://github.com/%s.git' "不可用
" 2023-03-01 测试正常
"let g:plug_url_format='https://ghproxy.com/https://github.com/%s.git'
" 2023-11-24
"let g:plug_url_format='https://github.moeyy.xyz/https://github.com/%s.git'

call plug#begin()

Plug 'morhetz/gruvbox'
"Plug 'joshdick/onedark.vim'
"Plug 'vim-airline/vim-airline'
Plug 'itchyny/lightline.vim'
"Plug 'Yggdroot/indentLine'
Plug 'preservim/nerdtree', { 'on': 'NERDTreeToggle' }
Plug 'tpope/vim-fugitive'
Plug 'majutsushi/tagbar'
Plug 'fholgado/minibufexpl.vim'
Plug 'vim-scripts/DoxygenToolkit.vim', { 'for': ['c', 'cpp'] }
"Plug 'aklt/plantuml-syntax', { 'for': 'uml' }
"Plug 'wannesm/wmgraphviz.vim', { 'for': 'dot' }
"Plug 'iamcco/markdown-preview.vim', { 'do': ':MarkdownPreview' }
"Plug 'mzlogin/vim-markdown-toc', { 'for': 'md' }
"Plug 'jszakmeister/markdown2ctags', { 'for': 'md' }
Plug 'Raimondi/delimitMate'
"Plug 'rkulla/pydiction', { 'for': 'py' }
"Plug 'Shougo/neocomplcache.vim'
Plug 'msanders/snipmate.vim'
Plug 'vim-utils/vim-man'
Plug 'junegunn/vim-easy-align'
"Plug 'edkolev/tmuxline.vim'
"Plug 'vim-scripts/OmniCppComplete', { 'for': ['c', 'cpp'] }
Plug 'lfv89/vim-interestingwords'
Plug 'zivyangll/git-blame.vim'
"Plug 'dense-analysis/ale', { 'for': ['c', 'cpp'] }
Plug 'Yggdroot/LeaderF', { 'do': ':LeaderfInstallCExtension' }
Plug 'bfrg/vim-cpp-modern', { 'for': ['c', 'cpp'] }
"Plug 'jayli/vim-easycomplete'
"Plug 'SirVer/ultisnips'
"Plug 'lifepillar/vim-mucomplete'
Plug 'ycm-core/YouCompleteMe', { 'do': './install.py --clang-completer' }
Plug 'ludovicchabant/vim-gutentags'

call plug#end()
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" => 主题颜色
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if has("termguicolors")
    	" enable true color
    	set termguicolors
else
	" for vim7
	set t_Co=256
endif

if 1
	">> gruvbox
	let g:gruvbox_italic = 1

	set background=dark
	"set background=light
	colorscheme gruvbox
else
	">> onedark
	let g:onedark_terminal_italics = 1

	colorscheme onedark
endif


" 插件设置

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"">>>>>>>>vim-airline
""显示在状态栏
"set laststatus=2
"
""let g:airline_theme="molokai"
"let g:airline_powerline_fonts = 1
"
"
""打开tabline功能,方便查看Buffer和切换,省去了minibufexpl插件
""let g:airline#extensions#tabline#enabled = 1
"
""状态栏显示当前行所在函数名,使能后打开大文件时耗时严重，影响体验，建议关闭
"let g:airline#extensions#tagbar#enabled = 0
"
"" 关闭状态显示空白符号计数
"let g:airline#extensions#whitespace#enabled = 0
"let g:airline#extensions#whitespace#symbol = '!'
"
"if !exists('g:airline_symbols')
"	let g:airline_symbols = {}
"endif
"
"" Unicode symbols
"let g:airline_left_sep = '»'
"let g:airline_left_sep = '▶'
"let g:airline_right_sep = '«'
"let g:airline_right_sep = '◀'
"let g:airline_symbols.linenr = ' '
"let g:airline_symbols.maxlinenr = 'Ξ'
"let g:airline_symbols.colnr = ' '
"let g:airline_symbols.branch = '⎇'
""let g:airline_symbols.paste = 'ρ'
""let g:airline_symbols.paste = 'Þ'
"let g:airline_symbols.paste = '∥'
""let g:airline_symbols.whitespace = 'Ξ'
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

">>>>>>>>lightline
"显示在状态栏
set laststatus=2

"默认组件: h g:lightline.component, 如relativepath
let g:lightline = {
    \ 'colorscheme': 'powerline',
    \ 'active': {
    \   'left': [ [ 'mode', 'paste' ],
    \             [ 'gitbranch' ],
    \             [ 'relativepath', 'readonly', 'modified' ],
    \           ],
    \   'right': [
    \             [ 'percent' ],
    \             [ 'lineinfo' ],
    \             [ 'fileformat', 'fileencoding', 'filetype' ],
    \             [ 'gutentags'],
    \            ],
    \ },
    \ 'component_function': {
    \   'gutentags': 'gutentags#statusline',
    \   'gitbranch': 'FugitiveHead',
    \ },
    \ }
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"">>>>>>>>indentLine
""空格缩进指示线
"let g:indentLine_enabled = 1
"let g:indentLine_fileType = ['c', 'h', 'cpp']
""let g:indentLine_char_list = ['┊']
"let g:indentLine_char_list = ['¦']
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

">>>>>>>>NERDTree
"树形目录
"指定鼠标模式（1.双击打开；2.单目录双文件；3.单击打开）
let NERDTreeMouseMode = 3
nmap <F4> :NERDTreeToggle<cr>
nmap ld :NERDTreeToggle<cr>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"">>>>>>>>vim-fugitive
""显示：当前模式、Git分支、文件路径、文件是否保存以及当前所载行和 列的信息
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

">>>>>>>>> Tagbar
let g:tagbar_width = 40
let g:tagbar_autofocus = 1
" 禁止首字母排序
let g:tagbar_sort = 0
" 单击选择
let g:tagbar_singleclick = 1
nmap <F8> :TagbarToggle<CR>
nmap lf :TagbarToggle<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

">>>>>>>>minibufexpl.vim
"
let g:miniBufExplUseSingleClick = 1 "Change buffer with single click on a buffer
let g:miniBufExplMaxSize = 1
"是否显示标号
let g:miniBufExplShowBufNumbers = 0

"下一个buf
nmap aa :bnext<cr>
"前一个buf
nmap zz :bprevious<cr>
":bdelete 删除当前buf

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

">>>>>>>>DoxygenToolkit.vim
" Doxygen风格的注释
let g:DoxygenToolkit_commentType = "C"
let g:DoxygenToolkit_briefTag_pre="@brief  "
let g:DoxygenToolkit_paramTag_pre="@param "
let g:DoxygenToolkit_returnTag="@returns   "
let g:DoxygenToolkit_dateTag="@date "
let g:DoxygenToolkit_versionTag="@version "
let g:DoxygenToolkit_versionString="1.0"
let g:DoxygenToolkit_authorName="winddoing, winddoing@sina.cn"
let s:licenseTag = "Copyright(C)\<enter>"
let s:licenseTag = s:licenseTag . "For free\<enter>"
let s:licenseTag = s:licenseTag . "All right reserved\<enter>"
let g:DoxygenToolkit_licenseTag = s:licenseTag

let g:DoxygenToolkit_briefTag_funcName="yes"
let g:doxygen_enhanced_color=1

nmap <F2> :DoxAuthor<cr>/
nmap <F3> :Dox<cr>/
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"">>>>>>>>plantuml-syntax
""vim + plantuml
"let g:plantuml_executable_script = 'java -jar ~/.vim/until/plantuml.jar'
"nnoremap <silent> <F5> :w<CR> :make<CR>:copen<CR>
"inoremap <silent> <F5> <Esc>:w<CR>:make<CR>:copen<CR>
"vnoremap <silent> <F5> :<C-U>:w<CR>:make<CR>:copen<CR>
"" Auto open
"autocmd BufWritePost  *.uml :silent !eog %:p:r.png &
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
"">>>>>>>>wmgraphviz.vim
"" vim + dot
"" Compiling: :GraphvizCompile, <LocalLeader>ll
"" Viewing: :GraphvizShow, <LocalLeader>lv
"" Interactive viewing + editing: :GraphvizInteractive, <LocalLeader>li
"" 导出PDF: :GraphvizCompilePDF
"autocmd BufWritePost *.dot :silent !dot -Tpng -o %<.png %
"autocmd BufWritePost *.dot :silent !eog %:p:r.png &
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
"">>>>>>>>markdown-preview.vim
"" vim + makedown + firefox
"let g:mkdp_path_to_chrome = "firefox"
"" 设置 chrome 浏览器的路径（或是启动 chrome（或其他现代浏览器）的命令）
"let g:mkdp_auto_start = 0
"" 设置为 1 可以在打开 markdown 文件的时候自动打开浏览器预览，只在打开markdown 文件的时候打开一次
"let g:mkdp_auto_open = 0
"" 设置为 1 在编辑 markdown 的时候检查预览窗口是否已经打开，否则自动打开预览窗口
"let g:mkdp_auto_close = 1
"" 在切换 buffer 的时候自动关闭预览窗口，设置为 0 则在切换 buffer 的时候不自动关闭预览窗口
"let g:mkdp_refresh_slow = 0
"" 设置为 1 则只有在保存文件，或退出插入模式的时候更新预览，默认为 0，实时更新预览
"
""nmap <silent> <F8> <Plug>MarkdownPreview
""imap <silent> <F8> <Plug>MarkdownPreview
"nmap M :MarkdownPreview <cr>
"nmap <silent> <F10> <Plug>StopMarkdownPreview
"imap <silent> <F10> <Plug>StopMarkdownPreview
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
"">>>>>>>vim-markdown-toc
""生成文章目录
"let g:vmt_auto_update_on_save = 1
""用于控制保存文件时是否自动更新已有文章目录，关闭为0
""let g:vmt_dont_insert_fence = 1
""关闭生成文章目录的时候会在前后插入 <!-- vim-markdown-toc -->
""使用命令：
"":GenTocGFM  生成 GFM 链接风格的文章目录。
"":GenTocRedcarpet  生成 Redcarpet 链接风格的文章目录。
"":UpdateToc 更新已有目录
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
"">>>>>>>>markdown2ctags
""目录大纲
"" Add support for markdown files in tagbar.
"let g:tagbar_type_markdown = {
"    \ 'ctagstype': 'markdown',
"    \ 'ctagsbin' : '~/.vim/plugged/markdown2ctags/markdown2ctags.py',
"    \ 'ctagsargs' : '-f - --sort=yes --sro=»',
"    \ 'kinds' : [
"        \ 's:sections',
"        \ 'i:images'
"    \ ],
"    \ 'sro' : '»',
"    \ 'kind2scope' : {
"        \ 's' : 'section',
"    \ },
"    \ 'sort': 0,
"\ }
"
"" 打开md文件时自动列出大纲列表
"autocmd BufWinEnter *.md :TagbarToggle<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

">>>>>>>>delimitMate
"自动补全引号(单引号/双引号/反引号), 括号(()[]{})]
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"">>>>>>>pydiction
""Python自动补全
"let g:pydiction_location = '~/.vim/plugged/pydiction/complete-dict'
"let g:pydiction_menu_height = 5
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"">>>>>>>>>>neocomplcache.vim
"" 提示补全
"let g:neocomplcache_enable_at_startup = 1
"let g:neocomplcache_force_overwrite_completefunc = 1
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"">>>>>>>>>>snipmate.vim
"" 自动补全代码块，如main+<Tab>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

">>>>>>>>>vim-utils/vim-man
"vim中使用man 操作：Shift + k
" open man page for word under cursor in a vertical split
nmap K <Plug>(Vman)
" open man page for word under cursor in a horizontal split
"nmap K <Plug>(Man)
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

">>>>>>>>>vim-easy-align
" 对齐
" Start interactive EasyAlign in visual mode (e.g. vipga)
xmap ga <Plug>(EasyAlign)
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
nmap ga <Plug>(EasyAlign)
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"">>>>>>>>>tmuxline.vim
""
"let g:tmuxline_preset = {
"			\'a'    : '#S',
"			\'b'    : '#W',
"			\'c'	  : ['#(whoami)'],
"			\'win'  : ['#I', '#W'],
"			\'cwin' : ['#I', '#W'],
"			\'x'	  : ['CPU:[#(cat /proc/cpuinfo | grep "processor" | wc -l)]'],
"			\'y'    : ['#(date +" %Y-%m-%d %H:%M")','%a'],
"			\'z'    : '#H',
"			\'options' : {'status-justify' : 'left'}}
"let g:tmuxline_separators = {
"			\ 'left' : '',
"			\ 'left_alt': '>',
"			\ 'right' : '',
"			\ 'right_alt' : '<',
"			\ 'space' : ' '}
"
"let g:tmuxline_powerline_separators = 0
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"">>>>>>>>>>>>>OmniCppComplete
""C++补全
""ctags -R --c++-kinds=+pl --fields=+iaS --extra=+q
"nmap c++ :!ctags -R --c++-kinds=+pl --fields=+iaS --extras=+q --language-force=C++<cr>
"let OmniCpp_MayCompleteDot = 1 " autocomplete with .
"let OmniCpp_MayCompleteArrow = 1 " autocomplete with ->
"let OmniCpp_MayCompleteScope = 1 " autocomplete with ::
"let OmniCpp_SelectFirstItem = 2
"let OmniCpp_NamespaceSearch = 2
"let OmniCpp_ShowPrototypeInAbbr = 1
"let OmniCpp_GlobalScopeSearch=1
"let OmniCpp_DisplayMode=1
"let OmniCpp_DefaultNamespaces=["std"]
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

">>>>>>>>>>>>>vim-interestingwords
"用不同颜色高亮感兴趣的单词
"Highlight with <Leader>k
"Navigate highlighted words with n and N
"Clear every word highlight with <Leader>kk throughout the buffer
nnoremap <silent> <leader>k :call InterestingWords('n')<cr>
nnoremap <silent> <leader>kk :call UncolorAllWords()<cr>

nnoremap <silent> n :call WordNavigation('forward')<cr>
nnoremap <silent> N :call WordNavigation('backward')<cr>

let g:interestingWordsRandomiseColors = 1
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

">>>>>>>>>>>>>git-blame.vim
"查看当前行代码的提交记录
nmap gb :<C-u>call gitblame#echo()<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"">>>>>>>>>>>>>ale
""静态语法检测,依赖clang
"
""只在保存文件时进行语法检测
""文件内容发生变化时不进行检查
"let g:ale_lint_on_text_changed = 'never'
""打开文件时不进行检查
"let g:ale_lint_on_enter = 0
"
""始终开启标志列
"let g:ale_sign_column_always = 1
"let g:ale_set_highlights = 0
"
""普通模式下，sp前往上一个错误或警告，sn前往下一个错误或警告
"nmap sp <Plug>(ale_previous_wrap)
"nmap sn <Plug>(ale_next_wrap)
"
""<Leader>d查看错误或警告的详细信息
"nmap <Leader>l :ALEDetail<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

">>>>>>>>>>>>>>>LeaderF
" 模糊查找
let g:Lf_WorkingDirectoryMode = 'AF'
let g:Lf_RootMarkers = ['.git', '.svn', '.hg', '.project', '.root']
let g:Lf_WildIgnore={'file':['*.vcproj', '*.vcxproj'],'dir':[]}
"开启快捷键
let g:Lf_ShortcutF = '<c-p>'
"关闭图标显示
let g:Lf_ShowDevIcons = 0

"实时检索
let g:Lf_UseVersionControlTool=1 "default value, can ignore
let g:Lf_DefaultExternalTool='rg'

"映射列表选择到方向键
let g:Lf_CommandMap = {'<C-K>': ['<Up>'], '<C-J>': ['<Down>']}
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

">>>>>>>>>>>>>>vim-cpp-modern
" C/C++语法高亮
" Disable function highlighting (affects both C and C++ files)
let g:cpp_function_highlight = 1

" Enable highlighting of C++11 attributes
let g:cpp_attributes_highlight = 1

" Highlight struct/class member variables (affects both C and C++ files)
let g:cpp_member_highlight = 1

" Put all standard C and C++ keywords under Vim's highlight group 'Statement'
" (affects both C and C++ files)
let g:cpp_simple_highlight = 1
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"">>>>>>>>>>>>>vim-easycomplete
"set updatetime=300
""let g:easycomplete_snips_enable = 0
"" Highlight the symbol when holding the cursor
"let g:easycomplete_cursor_word_hl = 0
"" Using nerdfont is highly recommended
""let g:easycomplete_nerd_font = 1
""取消tab触发补全选项
"let g:easycomplete_tab_trigger=""
"" 禁止语法诊断
"let g:easycomplete_diagnostics_enable = 0
"let g:easycomplete_diagnostics_hover = 0
"" 禁用Tabnine
"let g:easycomplete_tabnine_enable = 0
"" 打开文件时禁止检查是否安装了lsp
"let g:easycomplete_lsp_checking = 0
"let g:easycomplete_signature_enable = 0
"" 不进行默认快捷键绑定
"let g:easycomplete_typing_binding_done = 1
"
"" GoTo code navigation
""noremap gr :EasyCompleteReference<CR>
""noremap gd :EasyCompleteGotoDefinition<CR>
""noremap rn :EasyCompleteRename<CR>
""noremap gb :BackToOriginalBuffer<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"">>>>>>>>>>>>>vim-mucomplete
""set shortmess+=c   " Shut off completion messages
""set belloff+=ctrlg " Add only if Vim beeps during completion
"set completeopt-=preview
"set completeopt+=longest,menuone,noselect
"let g:mucomplete#enable_auto_at_startup = 1
"let g:mucomplete#completion_delay = 1
"let g:mucomplete#buffer_relative_paths = 1
"
"let g:mucomplete#user_mappings = { 'sqla' : "\<c-c>a" }
"let g:mucomplete#chains = { 'sql' : ['file', 'sqla', 'keyn'] }
"" The following line assumes `brew install llvm` in macOS
"let g:clang_library_path = '/usr/lib/llvm-18/lib/libclang.so.1'
"let g:clang_user_options = '-std=c++14'
"let g:clang_complete_auto = 1
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

">>>>>>>>>>>>>YouCompleteMe
" 指定配置文件路径
"let g:ycm_global_ycm_extra_conf='~/.vim/plugged/YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py'
let g:ycm_global_ycm_extra_conf='~/.vim/.ycm_extra_conf.py'
" 允许自动加载配置文件（避免手动确认）
let g:ycm_confirm_extra_conf = 0
let g:ycm_auto_trigger = 1                      " 输入时自动触发补全
let g:ycm_auto_trigger_delay = 300		" 自动触发补全时延300ms
let g:ycm_min_num_of_chars_for_completion = 3   " 输入3个字符即触发补全
let g:ycm_max_num_candidates = 50               " 限制补全项数量
" 保留语法高亮，但关闭 YCM 错误提示
let g:ycm_show_diagnostics_ui = 0              " 关闭 YCM 自带的错误提示（可选）

" 强制启用 clangd（YCM 默认启用）
let g:ycm_use_clangd = 1
let g:ycm_clangd_binary_path = '/usr/bin/clangd'  " 指定 clangd 路径（需先安装 clangd）

" 解除 YCM 的强制 Tab 映射
let g:ycm_key_list_select_completion = ['<C-n>', '<Down>']  " 改用其他按键导航补全项
let g:ycm_key_list_previous_completion = ['<C-p>', '<Up>']

let g:ycm_collect_identifiers_from_tags_files=1 " 开启 YCM 基于标签引擎
"let g:ycm_cache_omnifunc=0 " 禁止缓存匹配项,每次都重新生成匹配项

" 开启语法补全
let g:ycm_seed_identifiers_with_syntax=1 " 语法关键字补全

let g:ycm_complete_in_comments = 1 "在注释输入中也能补全
let g:ycm_complete_in_strings = 1 "在字符串输入中也能补全
let g:ycm_collect_identifiers_from_comments_and_strings = 1 "注释和字符串中的文字也会被收入补全

" 文件路径补全增强
let g:ycm_filepath_completion_use_working_directory = 1  " 基于工作目录补全路径

" 函数跳转
"" 跳转到声明
"nnoremap <leader>gd :YcmCompleter GoToDefinition<CR>
"" 跳转到实现
"nnoremap <leader>gi :YcmCompleter GoToImplementation<CR>
"" 查找所有引用
"nnoremap <leader>gr :YcmCompleter GoToReferences<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

">>>>>>>>>>>>>vim-gutentags
"自动代码索引生成工具
" 配置调试，输出详细日志
"let g:gutentags_trace = 1
" gutentags 搜索工程目录的标志，当前文件路径向上递归直到碰到这些文件/目录名
let g:gutentags_project_root = ['.root', '.svn', '.git', '.hg', '.project']

" 所生成的数据文件的名称后缀,默认使用-分隔
let g:gutentags_ctags_tagfile = 'tags'

"let g:gutentags_ctags_options_file = ''
"let g:gutentags_options_file = ''

" 同时开启ctags和gtags支持：
let g:gutentags_modules = []
if executable('ctags')
	let g:gutentags_modules += ['ctags']
endif
if executable('gtags-cscope') && executable('gtags')
	let g:gutentags_modules += ['gtags_cscope']
endif

" 将自动生成的ctags/gtags文件全部放入~/.cache/tags目录中，避免污染工程目录
let s:vim_tags = expand('~/.cache/tags')
let g:gutentags_cache_dir = s:vim_tags
if !isdirectory(s:vim_tags)
   silent! call mkdir(s:vim_tags, 'p')
endif

" 配置ctags的参数，老的 Exuberant-ctags 不能有--extra=+q，注意
let g:gutentags_ctags_extra_args = ['--fields=+niazS']
let g:gutentags_ctags_extra_args += ['--c++-kinds=+px']
let g:gutentags_ctags_extra_args += ['--c-kinds=+px']

" Get ctags version
let g:ctags_version = system('ctags --version')[0:8]

" 如果使用universal-ctags需要增加下面一行，老的Exuberant-ctags不能加下一行
if g:ctags_version == "Universal"
	let g:gutentags_ctags_extra_args += ['--extras=+q', '--output-format=e-ctags']
endif

" 智能文件列表命令配置
" sudo apt install fd-find
let g:gutentags_file_list_command = {
    \ 'markers': {
        \ '.git': 'git ls-files --cached --others --exclude-standard',
        \ '.hg': 'hg files',
        \ 'default': 'fd --type f --hidden --exclude .git'
    \ },
    \ 'append_path_separator': 0
\ }

" 禁用 gutentags 自动加载 gtags 数据库的行为
let g:gutentags_auto_add_gtags_cscope = 1
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" => ctag配置
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set tags=./tags;,tags
set path+=include;


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" => cscope配置
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 添加cscope数据库到当前vim
if has("cscope")
    set csprg=/usr/bin/cscope " 指定用来执行cscope的命令
    set csto=1 " 设置cstag命令查找次序：0先找cscope数据库再找标签文件；1先找标签文件再找cscope数据库
    set cst " 同时搜索cscope数据库和标签文件
    set nocsverb
    if filereadable("cscope.out") " 若当前目录下存在cscope数据库，添加该数据库到vim
        cs add cscope.out
    endif
    set csverb
endif

" 查找本 C 符号
nmap <Leader>s :cs find s <C-R>=expand("<cword>")<CR><CR>
" 查找本定义
nmap gd :cs find g <C-R>=expand("<cword>")<CR><CR>
" 查找本函数调用的函数
nmap <Leader>d :cs find d <C-R>=expand("<cword>")<CR><CR>
" 查找调用本函数的函数
nmap <Leader>c :cs find c <C-R>=expand("<cword>")<CR><CR>
" 查找本字符串
nmap <Leader>t :cs find t <C-R>=expand("<cword>")<CR><CR>
" 查找本 egrep 模式
nmap <Leader>e :cs find e <C-R>=expand("<cword>")<CR><CR>
" 查找本文件
nmap <Leader>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
" 查找包含本文件的文件
nmap <Leader>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>

" Ctrl+o 回到原位置
" Ctrl+i 追踪之前跳转

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" => 日志文件特殊字段高亮
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
au BufNewFile,BufRead *.log setfiletype log  " ~/.vim/syntax/log.vim

source ~/.vim/new_file_head.vimrc
